/**
 * @param {number} x
 * @param {number} n
 * @return {number}
 */
 var myPow = function(x, n) {
    if(n==0){
        return 1;
    }
    let res=x;
    if(n>0){
        res=nompow(x,n);
    }
    else{
        res=1/nompow(x,-n);
    }
    function nompow(x,n){
        let num=2,res=x;
        for(;num<=n;){
            res*=res;
            console.log(num,res);
            num*=2;
        }
        num=num/2;
        while(num<n){
            res*=x;
            console.log(num);
            num++;
        }
        return res;
    }
    return res;
};
console.log(myPow(0.8,18));